﻿@{
    ViewData["Title"] = "Index";
    Layout = "_OridinaryPage";
}
@using Dapper_Core.Web
@using Dapper_Core.Common

@section Header{
    <link rel="stylesheet" href="~/js/plugins/bootstrap-table/bootstrap-table.css" />
    <link rel="stylesheet" href="~/js/plugins/jquery-treegrid/css/jquery.treegrid.css" />
}

<section>
    <!--<h2>
        <small></small>
    </h2>-->
    <ol class="breadcrumb breadcrumb-pd clear-mgb bg-transparent">
        <li><a href="#"><i class="fa fa-dashboard"></i> 代理商信息管理</a></li>
        <li class="active">代理商信息</li>
    </ol>
</section>
<!-- Main content -->
<section class="content-mini clear-pdt clear-pdb">
    <div class="row">
        <div class="col-xs-12">
            <div class="box border-top-width-1">
                <!--<div class="box-header">
                    <h3 class="box-title"></h3>
                </div>-->
                <!-- /.box-header -->
                <div class="box-body">
                    <form class="form-horizontal" id="dataForm">
                        <div class="form-group">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-xs-12">
                                        <div class="row">
                                            <div class="col-xs-3">
                                                <label for="RepresentativeOffice" class="col-xs-3 control-label   text-left pd-lft pd-rt">代表处</label>
                                                <div class="col-xs-9 pd-lft">
                                                    <input type="text" class="form-control enter" id="RepresentativeOffice" name="RepresentativeOffice">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="Office" class="col-xs-3 control-label   text-left pd-lft pd-rt">办事处</label>
                                                <div class="col-xs-9 pd-lft">
                                                    <input type="text" class="form-control enter" id="Office" name="Office">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="City" class="col-xs-3 control-label   text-left pd-lft pd-rt">地市</label>
                                                <div class="col-xs-9 pd-lft">
                                                    <input type="text" class="form-control enter" id="City" name="City">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="" class="col-xs-3 control-label text-left pd-lft pd-rt">申请时间</label>
                                                <div class="col-xs-9 ">
                                                    <div class="row">
                                                        <div class="col-xs-12  input-group">
                                                            <input type="text" class="form-control Wdate Wdate-self col-xs-4 border-right-none enter" id="CreateDateStart"
                                                                   name="CreateDate" onFocus="WdatePicker({lang:'zh-cn',maxDate:'#F{\$dp.$D(\'CreateDateEnd\')}'})">
                                                            <div class="input-group-addon border-left-none border-right-none">至</div>
                                                            <input type="text" class="form-control Wdate Wdate-self col-xs-4 border-left-none enter" id="CreateDateEnd"
                                                                   name="CreateDateEnd" onFocus="WdatePicker({lang:'zh-cn',minDate:'#F{\$dp.$D(\'CreateDateStart\')}'})">
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-xs-12">
                                        <div class="row">
                                            <div class="col-xs-3">
                                                <label for="AgentName" class="col-xs-3 control-label text-left pd-lft pd-rt">代理商名称</label>
                                                <div class="col-xs-9 pd-lft">
                                                    <input type="text" class="form-control enter" id="AgentName" name="AgentName">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="AgentCode" class="col-xs-3 control-label text-left pd-lft pd-rt">代理商编码</label>
                                                <div class="col-xs-9 pd-lft">
                                                    <input type="text" class="form-control enter" id="AgentCode" name="AgentCode">
                                                </div>
                                            </div>
                                            <div class="col-xs-3">
                                                <label for="AccountFile" class="col-xs-3 control-label text-left pd-lft pd-rt">导入文件</label>
                                                <div class="col-xs-9 pd-lft">
                                                    <input type="file" id="AccountFile" name="AccountFile" class="form-control" />
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div style="text-align:center;margin-top:10px;">
                                    <button type="button" class="btn btn-blue btnWidth120 boxShadowNone btnMaRight" id="btnCancel">重置</button>
                                    <button type="button" class="btn btn-blue btnWidth120 boxShadowNone btnMaRight" id="btnSearsh">查询</button>
                                    <button type="button" class="btn btn-blue btnWidth120 boxShadowNone btnMaRight" id="btnAdd">新增</button>
                                    <button type="submit" class="btn btn-blue btnWidth120 boxShadowNone btnMaRight" onclick='this.form.action="@Url.Action("ExportToCsv")";'>导出</button>
                                    <button type="submit" class="btn btn-blue btnWidth120 boxShadowNone" id="btnImport">导入</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
        <!-- /.col -->
    </div>
    <!-- /.row -->
    <div class="table-responsive">
        <table id="dataInfos" class="table table-bordered text-nowrap"></table>
    </div>
    @*<div class="row">
            <div class="col-xs-12">
                <div class="box  box-success clear-mgb clearBoxTopBorder clearShadow">
                    <!--<div class="box-header">
                            <h3 class="box-title">审批记录</h3>
                        </div>-->
                    <!-- /.box-header -->
                    <div class="box-body clear-pd table-responsive">
                        <!--<table id="dataWorkflowNode" class="table table-bordered table-hover"></table>-->
                        <table id="dataInfos" class="table person-table-index text-nowrap"></table>
                    </div>
                </div>
            </div>
        </div>*@
</section>
<!-- /.content -->
<!-- addModal---start -->
<style type="text/css">
    #addNodeTable {
        margin: 0 auto;
        border-collapse: collapse;
    }

        #addNodeTable th, #addNodeTable td {
            border: 1px solid #888;
            padding: 5px 10px;
            text-align: center;
        }

        #addNodeTable a {
            color: rgb(0,162,232);
        }

        #addNodeTable select {
            height: 23px;
        }

        #addNodeTable input {
            width: 130px;
        }

    .bigWidth {
        width: 1000px;
    }
</style>
<div id="addModal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="addModal">
    <div class="modal-dialog modal-md bigWidth" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加代理商域账号信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="addForm">
                    <input type="hidden" id="addNodeJson" name="nodeJson" />
                    <div class="form-group">
                        <label for="addCreator" class="col-sm-1 control-label">代申请人</label>
                        <div class="col-sm-3">
                            <input type="text" readonly="readonly" class="form-control" id="addCreator" name="Creator" placeholder="代申请人" value="@SessionUtility.GetBasicUserInfo().PinyinCode">
                        </div>
                        <label for="addWorkflowCode" class="col-sm-1 control-label">申请时间</label>
                        <div class="col-sm-3">
                            <input type="text" readonly="readonly" class="form-control" id="addCreationDate" name="CreationDate" placeholder="申请时间" value="@DateTime.Now">
                        </div>
                    </div>
                </form>
                <table id="addNodeTable">
                    <tr><th>代表处</th><th>办事处</th><th>地市</th><th>代理商名称</th><th>代理商编码</th><th>备注</th><th>操作</th></tr>
                    <tr class="nodeTr" id="addNodeTr1">
                        <td><input type="text" name="RepresentativeOffice" value="" /></td>
                        <td><input type="text" name="Office" value="" /></td>
                        <td><input type="text" name="City" value="" /></td>
                        <td><input type="text" name="AgentName" value="" /></td>
                        <td><input type="text" name="AgentCode" value="" onkeyup='this.value=this.value.replace(/\D/gi,"")' onblur="checkAgentExist(this)" maxlength="5" /></td>
                        <td><input type="text" name="Remark" value="" /></td>
                        <td><a class="addDeleteNodeTr">删除</a></td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="btnAddAddNode" class="btn btn-primary">添加行</button>
                <button type="button" id="btnAddSubmit" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    //添加节点tr
    $("#btnAddAddNode").click(function () {
        var currentMaxStep = $("#addNodeTable tr").filter(".nodeTr").size();
        var nextStep = currentMaxStep + 1;
        var firstTr = $("#addNodeTable tr.nodeTr:eq(0)");
        var newTr = firstTr.clone(true);
        newTr.find("input").val('');

        //修改id
        newTr.attr("id", "addNodeTr" + nextStep);
        newTr.attr("id", "addNodeTr" + nextStep);
        newTr.appendTo($("#addNodeTable"));
    });

    //删除节点tr
    $(".addDeleteNodeTr").click(function () {
        if (confirm('确认删除吗？') == true) {
            var btnDel = $(this); //得到点击的按钮对象
            var tr = btnDel.parent("td").parent("tr"); //得到父tr对象;
            if (tr.attr("id") == "addNodeTr1") {
                alert('第一行不能删除!'); //第一行是克隆的基础，不能删除
                return;
            }
            else {
                tr.remove();
                addResetNo();
            }
        }
    });

    //重新设置table中所有节点tr的序号和id
    function addResetNo() {
        var trs = $("#addNodeTable .nodeTr");
        trs.each(function (i, tr) {
            var index = i + 1;
            $(tr).attr("id", "addNodeTr" + index);
        });
    }

    $("#btnAddSubmit").click(function () {
        var creator = $("#addCreator").val();
        var creationDate = $("#addCreationDate").val();
        if (creator == null || creator.trim() == "") {
            alert("代申请人不能为空！");
            return;
        }
        if (creationDate == null || creationDate.trim() == "") {
            alert("申请时间不能为空！");
            return;
        }
        if (!addSetNodeJson()) return;
        IndexBtnDisabled();
        $.ajax({
            type: "post",
            url: "/Agent/AgentSamAccount/Add",
            data: $("#addForm").serialize(),
            dataType: "json",
            success: function (data) {
                if (data.success) {
                    alert(data.message);
                    $("#addNodeTable .nodeTr:gt(0)").remove();
                    $(".nodeTr").find("input").val('');
                    $("#addModal").modal('hide');
                    $("#btnSearsh").click();
                } else {
                    alert(data.message);
                }
                IndexBtnEnabled();
            },
            error: function (err) { }
        });
    });

    //1、检查节点数据的完整性
    //2、将节点数据转化成json字符串并保存到隐藏控件中（提交时会传递到后台）
    function addSetNodeJson() {
        var trs = $("#addNodeTable .nodeTr");
        var nodeDataIsValid = true;
        trs.each(function (i, tr) {
            var sameCount = 0;
            var index = i + 1;
            var representativeOffice = $(tr).find("input[name='RepresentativeOffice']").val();
            var office = $(tr).find("input[name='Office']").val();
            var city = $(tr).find("input[name='City']").val();
            var agentName = $(tr).find("input[name='AgentName']").val();
            var agentCode = $(tr).find("input[name='AgentCode']").val();
            var remark = $(tr).find("input[name='Remark']").val();
            if (IsNullOrEmpty(representativeOffice)) {
                alert("第" + index + "行的代表处不能为空！");
                $(tr).find("input[name='RepresentativeOffice']").focus();
                nodeDataIsValid = false;
                return false;
            }
            if (IsNullOrEmpty(office)) {
                alert("第" + index + "行的办事处不能为空！");
                $(tr).find("input[name='Office']").focus();
                nodeDataIsValid = false;
                return false;
            }
            if (IsNullOrEmpty(city)) {
                alert("第" + index + "行的地市不能为空！");
                $(tr).find("input[name='City']").focus();
                nodeDataIsValid = false;
                return false;
            }
            if (IsNullOrEmpty(agentName)) {
                alert("第" + index + "行的代理商名称不能为空！");
                $(tr).find("input[name='AgentName']").focus();
                nodeDataIsValid = false;
                return false;
            }
            if (IsNullOrEmpty(agentCode)) {
                alert("第" + index + "行的代理商编码不能为空！");
                $(tr).find("input[name='AgentCode']").focus();
                nodeDataIsValid = false;
                return false;
            }
            trs.each(function (i, tr) {
                var temp = $(tr).find("input[name='AgentCode']").val();
                if (temp == agentCode) sameCount += 1;
            });
            if (sameCount > 1) {
                alert("第" + index + "行的代理商编码已重复！");
                $(tr).find("input[name='AgentCode']").val();
                $(tr).find("input[name='AgentCode']").focus();
                nodeDataIsValid = false;
                return false;
            }
            if (IsNullOrEmpty(remark)) {
                alert("第" + index + "行的备注不能为空！");
                $(tr).find("input[name='Remark']").focus();
                nodeDataIsValid = false;
                return false;
            }
        });
        if (!nodeDataIsValid) return false;
        var json = '[';
        trs.each(function (i, tr) {
            json += '{';
            json += '"RepresentativeOffice":"' + $(tr).find("input[name='RepresentativeOffice']").val() + '",';
            json += '"Office":"' + $(tr).find("input[name='Office']").val() + '",';
            json += '"City":"' + $(tr).find("input[name='City']").val() + '",';
            json += '"AgentName":"' + $(tr).find("input[name='AgentName']").val() + '",';
            json += '"AgentCode":"' + $(tr).find("input[name='AgentCode']").val() + '",';
            json += '"Remark":"' + $(tr).find("input[name='Remark']").val() + '"';
            json += '},';
        });
        if (json.length > 1) {
            json = json.substring(0, json.length - 1);
        }
        json += "]";
        $("#addNodeJson").val(json);
        return true;
    }
</script>
<!-- addModal---end -->
<!-- updateModal---start -->
<div id="updateModal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="updateModal">
    <div class="modal-dialog modal-md" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改代理商域账号信息</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="updateForm">
                    <input type="hidden" id="updateId" name="Id" value="" />
                    <div class="form-group">
                        <label for="representativeOffice" class="col-sm-2 control-label">代表处</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="representativeOffice" name="RepresentativeOffice" placeholder="代表处" maxlength="100">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="office" class="col-sm-2 control-label">办事处</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="office" name="Office" placeholder="办事处" maxlength="100">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="City" class="col-sm-2 control-label">地市</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="city" name="City" placeholder="地市" maxlength="100">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="agentCode" class="col-sm-2 control-label">代理商编码</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="agentCode" name="AgentCode" placeholder="代理商编码" maxlength="100" readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="agentName" class="col-sm-2 control-label">代理商名称</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="agentName" name="AgentName" placeholder="代理商名称" maxlength="100">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="remark" class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control" id="remarks" name="Remarks" placeholder="备注" maxlength="200">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="btnEditSubmit" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#btnEditSubmit").click(function () {
        var representativeOffice = $("#representativeOffice").val();
        var office = $("#office").val();
        var city = $("#city").val();
        var agentName = $("#agentName").val();
        var remark = $("#remarks").val();
        if (IsNullOrEmpty(representativeOffice)) {
            alert("代表处不能为空！");
            $("#representativeOffice").focus();
            return;
        }
        if (IsNullOrEmpty(office)) {
            alert("办事处不能为空！");
            $("#office").focus();
            return;
        }
        if (IsNullOrEmpty(city)) {
            alert("地市不能为空！");
            $("#city").focus();
            return;
        }
        if (IsNullOrEmpty(agentName)) {
            alert("代理商名称不能为空！");
            $("#agentName").focus();
            return;
        }
        if (IsNullOrEmpty(remark)) {
            alert("备注不能为空！");
            $("#remark").focus();
            return;
        }
        IndexBtnDisabled();
        $.ajax({
            type: "post",
            url: "/Agent/AgentSamAccount/UpdateSamAccount",
            data: $("#updateForm").serialize(),
            dataType: "json",
            success: function (data) {
                if (data.Success) {
                    alert(data.Message);
                    $("#representativeOffice").val('');
                    $("#office").val('');
                    $("#city").val('');
                    $("#agentName").val('');
                    $("#remark").val('');
                    $("#updateModal").modal('hide');
                    refreshDataInfos();
                } else {
                    alert(data.Message);
                }
                IndexBtnEnabled();
            },
            error: function (err) { }
        });
    });
</script>
<!-- updateModal---end -->

@section Scripts{
    <script src="~/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="~/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script src="~/js/plugins/bootstrap-table/extensions/treegrid/bootstrap-table-treegrid.js"></script>
    <script src="~/js/plugins/jquery-treegrid/js/jquery.treegrid.js"></script>
    <script src="~/js/plugins/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript">
        $(function () {
            //1.初始化Table
            var oTable = new TableInit();
            oTable.Init();

            $(".enter").keypress(function (e) {
                if (e.keyCode == 13) {
                    refreshDataInfos();
                    return false;
                }
            });
        });

        var TableInit = function () {
            var oTableInit = new Object();
            //初始化Table
            oTableInit.Init = function () {
                $('#dataInfos').bootstrapTable({
                    url: '/Agent/AgentSamaccount/GetPageList',   //请求后台的URL（*）
                    method: 'get',                      //请求方式（*）
                    //toolbar: '#toolbar',                //工具按钮用哪个容器
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    sortable: false,                    //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: oTableInit.queryParams,//传递参数（*）
                    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                      //初始化加载第一页，默认第一页
                    pageSize: 15,                       //每页的记录行数（*）
                    pageList: [10, 15, 20, 30, 50],     //可供选择的每页的行数（*）
                    search: false,                      //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    searchOnEnterKey: true,
                    strictSearch: true,
                    showColumns: false,                 //是否显示所有的列
                    showRefresh: false,                 //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    clickToSelect: true,                //是否启用点击选中行
                    //height: 670,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    uniqueId: "Id",                     //每一行的唯一标识，一般为主键列
                    showToggle: false,                  //是否显示详细视图和列表视图的切换按钮
                    cardView: false,                    //是否显示详细视图
                    detailView: false,                  //是否显示父子表
                    columns: [
                        {
                            field: 'Id',
                            title: '操作',
                            halign: 'left',
                            width: '100px',
                            formatter: 'operateFormatter'
                        },
                        {
                            field: 'RepresentativeOffice',
                            title: '代表处',
                            halign: 'left'
                        }, {
                            field: 'Office',
                            title: '办事处',
                            halign: 'left'
                        }, {
                            field: 'City',
                            title: '地市',
                            halign: 'left'
                        }, {
                            field: 'AgentCode',
                            title: '代理商编码',
                            halign: 'left'
                        }, {
                            field: 'AgentName',
                            title: '代理商名称',
                            halign: 'left'
                        }, {
                            field: 'SamAccount',
                            title: '域账号',
                            halign: 'left'
                        }, {
                            field: 'Password',
                            title: '初始密码',
                            halign: 'left'
                        }, {
                            field: 'State',
                            title: '状态',
                            halign: 'left'
                        }, {
                            field: 'Creator',
                            title: '创建人',
                            halign: 'left'
                        }, {
                            field: 'CreateDate',
                            title: '创建时间',
                            halign: 'left',
                            width: '120px',
                            formatter: function (value, row, index) {
                                return getFormatDate(value)
                            }
                        }],
                    onLoadSuccess: function (res) {  //加载成功时执行
                        //console.info(res);
                    },
                    onLoadError: function () {  //加载失败时执行
                        //console.info("加载数据失败");
                    }
                });
            };

            //得到查询的参数
            oTableInit.queryParams = function (params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    rowsPerPage: params.limit,  //每页数据行数
                    offsetRows: params.offset,  //已偏移行数
                    RepresentativeOffice: $("#RepresentativeOffice").val(), //代表处
                    Office: $("#Office").val(),                             //办事处
                    City: $("#City").val(),                                 //城市
                    CreateDate: $("#CreateDateStart").val(),           //申请时间start
                    CreateDateEnd: $("#CreateDateEnd").val(),               //申请时间end
                    AgentName: $('#AgentName').val(),                       //代理商名称
                    AgentCode: $("#AgentCode").val(),                       //代理商编码
                    //search: params.search
                };
                return temp;
            };
            return oTableInit;
        };

        //格式化操作列的内容
        function operateFormatter(value, row, index) {
            var array = [];
            //登录人是当前审批人&&流程为待审批状态
            var v;
            if (row.state == "generated") {
                array.push('<a href="#" mce_href="#" style="padding-right:5px" onclick="AgentSamAccountClose(\'' + row.samAccount + '\',\'' + row.id + '\')">销户</a> ');
            }
            else if (row.state == "submitted") {
                array.push('<a href="#" mce_href="#" style="padding-right:5px" onclick="AgentSamAccountCreateAgain(\'' + row.samAccount + '\',\'' + row.id + '\')">重新申请</a> ');
            }
            else {
                v = "";
            }
            array.push("<a href='#' mce_href='#' onclick='UpdateAgentSamaccount(" + JSON.stringify(row) + ")'>修改</a> ");
            return array.join('');
        }

        $("#btnSearsh").click(function () {
            refreshDataInfos();
        });

        $("#btnCancel").click(function () {
            $("#RepresentativeOffice").val('');//代表处
            $("#Office").val('');              //办事处
            $("#City").val('');                //城市
            $("#CreateDateStart").val('');     //申请时间start
            $("#CreateDateEnd").val('');       //申请时间end
            $('#AgentName').val('');           //代理商名称
            $("#AgentCode").val('');           //代理商编码
        });

        $("#btnAdd").click(function () {
            $("#addModal").modal('show');
        });

        $("#btnImport").click(function () {
            var filePath = document.all.AccountFile.value;
            var formData = new FormData($("#dataForm")[0]);
            if (IsNullOrEmpty(filePath)) {
                alert("请选择文件！");
                return false;
            }
            var url = '@Url.Content("~/Agent/AgentSamaccount/ImportData")';
            $.ajax({
                url: url,
                data: formData,
                type: "post",
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (data) {
                    alert(data.Message);
                    return false;
                }
            });
            var file = document.getElementById("AccountFile");
            if (file.outerHTML) {
                file.outerHTML = file.outerHTML;
            }
            else {
                file.value = "";
            }
        });

        function refreshDataInfos() {
            $("#dataInfos").bootstrapTable('refresh');
        }

        function UpdateAgentSamaccount(row) {
            if (!window.confirm("确定修改本代理商域账号" + row.SamAccount + "？")) {
                return false;
            }
            $("#updateId").val(row.Id);
            $("#representativeOffice").val(row.RepresentativeOffice);
            $("#office").val(row.Office);
            $("#city").val(row.City);
            $("#agentName").val(row.AgentName);
            $("#agentCode").val(row.AgentCode);
            $("#remarks").val(row.Remarks);
            $("#updateModal").modal('show');
        }

        function checkAgentExist(_this) {
            var agentCode = $(_this).val();
            var agentId = $("#updateId").val();
            if (IsNullOrEmpty(agentCode)) return;
            $.ajax({
                type: "get",
                url: "/Agent/AgentSamaccount/IsExist",
                data: "agentCode=" + agentCode + "&agentId=" + agentId,
                dataType: "json",
                success: function (data) {
                    if (data.Exist) {
                        alert("本代理商编码已存在！");
                        $(_this).val('');
                        $(_this).focus();
                    }
                },
                error: function (err) { }
            });
        }
    </script>
}